package services

import (
	"go_web/src/domain"
	"go_web/src/repositories"
)

type UserService struct {
	up repositories.UserRepository
}

func NewUserService(up repositories.UserRepository) UserService {
	return UserService{up: up}
}

// Create 新建用户
func (us UserService) Create(user *domain.User) error {
	return us.up.Create(user)
}

// UpdateByID 修改用户
func (us UserService) UpdateByID(id uint, name string) error {
	return us.up.UpdateByID(id, name)
}

// DeleteByID 删除用户
func (us UserService) DeleteByID(id uint) error {
	return us.up.DeleteByID(id)
}

// FindByID 查询用户
func (us UserService) FindByID(id uint) (*domain.User, error) {
	return us.up.FindByID(id)
}

// FindByName 通过名称查询所有用户
func (us UserService) FindByName(name string) (*[]domain.User, error) {
	return us.up.FindByName(name)
}
